class Solution:
    def reverseWords(self, s: str) -> str:
        l = 0
        r = 0
        res = []
        for i in range(len(s)):
            if s[i]==" ":
                res.append(s[l:r][::-1])
                l = i+1
            r+=1
        if l < r:
             res.append(s[l:r][::-1])

        return " ".join(res)


